package yang.itcode.controller;

import cn.hutool.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yang.itcode.model.Result;
import yang.itcode.service.UserService;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody JSONObject user) {
        String name = user.getStr("name");
        String password = user.getStr("password");
        String jwt = userService.login(name,password);
        return Result.success(jwt);
    }

    @GetMapping("/info")
    public Result<JSONObject> getUserInfo(){
        JSONObject user = userService.getUserInfo();
        return Result.success(user);
    }
}
